package gui.listener;

import gui.MainFrame;

import java.io.File;

import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;

public class MyContentListener implements TreeSelectionListener {

	private MainFrame mainFrame;
	
	public MyContentListener(MainFrame mainFrame){
		this.mainFrame = mainFrame;
	}

	public void valueChanged(TreeSelectionEvent e){
		
		String  extension;
		int		dotPos;
		
		File directory=(File)e.getPath().getLastPathComponent();
		
		String  fileName = directory.getAbsolutePath();
		
		dotPos 		= fileName.lastIndexOf(".");
		extension 	= fileName.substring(dotPos);
		
		if(extension.equals(".pdf") || (extension.equals(".xml"))) {
			
			if(mainFrame.settingsPanel.jRadioButtonLocalFile.isSelected() && mainFrame.settingsPanel.jRadioButton2ndChart.isSelected()){
				
				mainFrame.path2nd		= directory.getAbsolutePath();
				mainFrame.extension2nd	= extension;
				
			}
			else{
				
				if(mainFrame.path1st.equals("")) {
					mainFrame.settingsPanel.setEnabled();
				}			
				
				mainFrame.path1st		= directory.getAbsolutePath();
				mainFrame.extension1st	= extension;
				
				if(mainFrame.settingsPanel.jRadioButtonRemoteFile.isSelected())
					mainFrame.path2nd = "";
				
			}
			
			mainFrame.updateIndex();
			mainFrame.updateChart();
			
		}
	}
	
}
